package in.wptrafficanalyzer.actionbarnavtab;

import java.util.ArrayList;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/** This is a listfragment class */
public class ExpensesFragment extends ListFragment {
	// static ArrayList<String> list = new ArrayList<String>();
	// static ArrayAdapter<String> adapter;
	// static ArrayList<String> dates = new ArrayList<String>();
	// static ArrayList<String> money = new ArrayList<String>();
	static ArrayList<RowList> rl = new ArrayList<RowList>();
	static RowListAdapter rla;
	static TextView mHeaderView;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		mHeaderView = (TextView) getActivity().getLayoutInflater().inflate(
				R.layout.header, null);
		mHeaderView.setText("");
		if (rla == null) {
			rl.add(new RowList("10/12/1990", "100.00"));
			rl.add(new RowList("11/12/1990", "120.00"));
		}
		setListAdapter(null);
		getListView().addHeaderView(mHeaderView);
		rla = new RowListAdapter(getActivity().getLayoutInflater(),
				R.layout.itemlayout, rl);
		setListAdapter(rla);

		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onStart() {
		super.onStart();
		getListView().setBackgroundResource(R.color.tostadoclaro);
		getListView()
				.setDivider(getResources().getDrawable(R.drawable.divider));

		getListView().setDividerHeight(4);
		/** Setting the multiselect choice mode for the listview */
		// getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	}

	// @Override
	// public void onResume() {
	// setListAdapter(null);
	// super.onResume();
	// }

	public static void addItem(String date, String cnt) {
		if (!cnt.endsWith(".00")) {
			cnt = cnt.concat(".00");
		}
		rl.add(new RowList(date, cnt));
		rla.notifyDataSetChanged();
	}

}
